<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <?php include 'inc/head.php'; ?>
  <style>
    .datatable a {
      font-size: small;
    }
  </style>
</head>

<body>
  <?php include 'inc/header.php'; ?>

  <div class="container">
    <div class="card mb-3">
      <div class="card-header">数据表</div>
      <div class="card-body row">
        <?php
        $res = $this->dbc->tables();
        if (!empty($res)) {
          $count = count($res);
          for ($i = 0; $i < $count; $i++) {
            $name = str_replace(DATA_PREFIX, '', $res[$i]);
            echo '<a href="' . M('admin', 'database', 'table', $res[$i]) . '" class="col-6 col-sm-3 text-truncate ' . ($res[$i] == $_GET['id'] ? 'text-black-50' : '') . '" title="点击查看表结构">' . $name . '</a>';
          }
        }
        ?>
      </div>
    </div>

    <table class="table table-sm table-bordered table-hover">
      <thead class="bg-light">
        <tr>
          <th>数据列名</th>
          <th>数据类型</th>
          <th>主键</th>
        </tr>
      </thead>
      <tbody>
        <?php
        if ($_GET['id']) {
          $res = $this->dbc->cols(str_safe($_GET['id']));
          foreach ($res as $val) {
            echo '<tr><td>' . $val['Field'] . '</td><td>' . $val['Type'] . '</td><td>' . $val['Key'] . '</td></tr>';
          }
        }
        ?>
      </tbody>
    </table>

  </div>

  <?php include 'inc/footer.php'; ?>

</body>

</html>